import { defineStore } from 'pinia'
import { ref } from  'vue'
import {userGetInfoService} from "@/api/user.js";

export const useUserStore =defineStore('m_user',()=>{
  const token = ref('')

  // 设置token
  const setToken = (newToken) => {
    token.value = newToken
  }
  // 移除token
  const removeToken = () => {
    token.value = ''
  }

  // 获取用户的基本信息
  const user = ref({})
  const getUser = async () => {
    // const res = await userGetInfoService()
    // console.log(res, '获取用户的基本信息')
    // user.value = res.data.data || {}
    user.value = {
      email: '17638593734@163.com',
      id: 10010,
      nickname: 'HuZong',
      user_pic: '@/assets/login.png',
      username: 'huzong'
    }
  }
  // 清空用户基本信息
  const setUser = () => {
    user.value = {}
  }

  return {
    token,
    setToken,
    removeToken,
    user,
    getUser,
    setUser
  }
},{
  persist: true
})
